/*
 * 统计模块业务统计门诊基础js
 * @author 杨腊梅
 * 2016/1/20
 * 
 */
$("#businessBase_monthDate").val(new Date().Format('yyyy'));
$('#tcm_businessBaseClinic_eCharts').css('height',orange.detailPage.getHeight());
$('#tcm_businessBaseClinic_eCharts').css('width',orange.detailPage.getWidth());
$('#tcm_businessBaseClinic_grid').datagrid({
	url:"d/out/table",
	queryParams:{orgGuid:$("#tcmcpdetail_guid").val(),
		year:$("#businessBase_monthDate").val()},
	singleSelect:true,
	rownumbers:true,
	columns:[[
	          {field:'month',title:'月份',width:'10%',sortable:true,halign:'center'},
	          {field:'amountNormal',title:'常规门诊人数',width:'10%',sortable:true,halign:'center'},
	          {field:'amountRemote',title:'远程门诊人数',width:'10%',sortable:true,halign:'center'},
	          {field:'amountPreliminary',title:'初诊人数',width:'12%',sortable:true,halign:'center'},
	          {field:'amountSubsequent',title:'复诊人数',width:'12%',sortable:true,halign:'center'},
	          {field:'amountTheLocal',title:'本地就诊',width:'12%',sortable:true,halign:'center'},
	          {field:'amountTheForeigner',title:'外来就诊',width:'12%',sortable:true,halign:'center'},
	          {field:'disNames',title:'最多病种',width:'20%',sortable:true,halign:'center',formatter:function(value){
	          	var value_other = value == null ? "" : value;
	        	return '<span title="' + value_other + '">' + value_other + '</span>';
	        }},
	          ]],
	pagination:true,
	sortable:true,
	sortName:'tcm_time',
	sortOrder:'asc'
});
/**
 * 查询
 */
function tcm_businessBaseClinic_query(){
	$('#tcm_businessBaseClinic_grid').datagrid({
		url:"d/out/table",
		queryParams:{orgGuid:$("#tcmcpdetail_guid").val(),
			year:$("#businessBase_monthDate").val()},
	})
	initbusinessBaseChartData();
}


/*
 * 图表数据初始化
 */
var tcm_myChart = echarts.init($('#tcm_businessBaseClinic_eCharts')[0]);

var tcm_serial_normal_clinic = [];
var tcm_serial_remote_clinic = [];
var tcm_serial_firsttime_clinic = [];
var tcm_serial_nonfirst_clinic = [];
var tcm_serial_local_clinic = [];
var tcm_serial_nonlocal_clinic = [];
var tcm_xData=[];
initbusinessBaseChartData();

function initbusinessBaseChartData(){
	$.ajax({
		url:"d/out/chart",
		type:"get",
		data:{orgGuid:$("#tcmcpdetail_guid").val(),
			year:$("#businessBase_monthDate").val()},
		success:function(data){
			tcm_serial_normal_clinic.length = 0;
			tcm_serial_remote_clinic.length = 0;
			tcm_serial_firsttime_clinic.length = 0;
			tcm_serial_nonfirst_clinic.length = 0;
			tcm_serial_local_clinic.length = 0;
			tcm_serial_nonlocal_clinic.length = 0;
			tcm_xData.length = 0;
			var tcm_initData = JSON.parse(data)
			for(var i=0; i<tcm_initData.length; i++) {
				tcm_serial_normal_clinic.push(tcm_initData[i].amountNormal);
				tcm_serial_remote_clinic.push(tcm_initData[i].amountRemote);
				tcm_serial_firsttime_clinic.push(tcm_initData[i].amountPreliminary);
				tcm_serial_nonfirst_clinic.push(tcm_initData[i].amountSubsequent);
				tcm_serial_local_clinic.push(tcm_initData[i].amountTheLocal);
				tcm_serial_nonlocal_clinic.push(tcm_initData[i].amountTheForeigner);
				tcm_xData.push(tcm_initData[i].period);
			}
			tcm_myChart.setOption(tcm_option);
		}
	});
}



/*
 * 设置图表格式
 */
tcm_option={
		grid:{
			show:false,
			bottom :'15%',
			top:'25%',
			height:'65%',
			width:'80%',
			left:'10%',
			right:'15%'
		},
		tooltip : {
			trigger : 'axis'
		},
		
		legend : {
			top : '8%',
			data : ['常规门诊人数', '远程门诊人数', '初诊人数', '复诊人数', '本地就诊', '外来就诊']
		},
		
		xAxis : [{
			type : 'category',
			boundaryGap : false,
			data : tcm_xData
		}],
		
		yAxis : [{
			type:'value'
		}],
		
		series : [
		  {
			  type : 'line',
			  name : "常规门诊人数",
			  smooth : true,
			  data : tcm_serial_normal_clinic
		  },
		  {
			  type : 'line',
			  name : "远程门诊人数",
			  smooth : true,
			  data : tcm_serial_remote_clinic
		  },
		  {
			  type : 'line',
			  name : "初诊人数",
			  smooth : true,
			  data : tcm_serial_firsttime_clinic
		  },
		  {
			  type : 'line',
			  name : "复诊人数",
			  smooth : true,
			  data : tcm_serial_nonfirst_clinic
		  },
		  {
			  type : 'line',
			  name : "本地就诊",
			  smooth : true,
			  data : tcm_serial_local_clinic
		  },
		  {
			  type : 'line',
			  name : "外来就诊",
			  smooth : true,
			  data : tcm_serial_nonlocal_clinic
		  }
		],
};

//使用刚指定的配置项和数据显示图表
tcm_myChart.setOption(tcm_option);